﻿using Abp.Authorization;
using Abp.Authorization.Roles;
using AbpProjectTemplate.Domain.Roles;
using AutoMapper;
using System.Linq;

namespace AbpProjectTemplate.Application.Roles.Dtos
{
    public class RoleMapProfile : Profile
    {
        public RoleMapProfile()
        {
            // Role and permission
            this.CreateMap<Permission, string>().ConvertUsing(r => r.Name);
            this.CreateMap<RolePermissionSetting, string>().ConvertUsing(r => r.Name);

            //CreateMap<RoleDto, Role>()
            //    .ForMember(t => t.Name, t => t.MapFrom(x => x.DisplayName));

            //CreateMap<RoleEditDto, Role>()
            //    .ForMember(t => t.Name, t => t.MapFrom(x => Guid.NewGuid().ToString("N")));

            this.CreateMap<Role, RoleDto>().ForMember(x => x.GrantedPermissions,
                opt => opt.MapFrom(x => x.Permissions.Where(p => p.IsGranted)));
        }
    }
}


